package followme.yaohuile.com.followme.adapter.recommend;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;

import java.util.List;

import followme.yaohuile.com.followme.R;
import followme.yaohuile.com.followme.bean.recommend.Discount;

/**
 * Created by Administrator on 15-11-15.
 */
public class RecommendDingyueGridViewAdapter extends BaseAdapter {
    private List<Discount> list;
    private Context context;
    private final BitmapUtils bitmapUtils;

    public RecommendDingyueGridViewAdapter(List<Discount> list, Context context) {
        this.list = list;
        this.context = context;
        bitmapUtils = new BitmapUtils(context);
    }

    @Override
    public int getCount() {
        int ret = 0;
        if (list != null) {
            ret = list.size();
        }
        return ret;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_recommend_dingyuegridview,null);
            vh = new ViewHolder();
            vh.image = (ImageView) convertView.findViewById(R.id.dingyueiv);
            vh.dingYuetv = (TextView) convertView.findViewById(R.id.dingyuetv);
            vh.dingYueDaZhe = (TextView) convertView.findViewById(R.id.dingyuedazhe);
            vh.dingYueQiJia = (TextView) convertView.findViewById(R.id.dingyueqijia);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        vh.dingYuetv.setText(list.get(position).getTitle());
      vh.dingYueDaZhe.setText(list.get(position).getPriceoff());
        String pri =  list.get(position).getPrice();
        String tm =pri.substring(pri.indexOf("<em>")+4, pri.lastIndexOf("</em>"));

        vh.dingYueQiJia.setText(tm+"元起");
        bitmapUtils.display(vh.image,list.get(position).getPhoto());
        return convertView;
    }
    class ViewHolder{
        ImageView image;
        TextView dingYuetv,dingYueDaZhe,dingYueQiJia;
    }
}
